﻿//********************************************************************************//
//创建日期：<创建日期，2016-05-10>
//创建作者：<郭登杰>
//功能说明：来函公共控件-受理按钮组
//********************************************************************************//

using System;
using System.Collections.Generic;
using Entity;
using BLL;
using BLL.Access;
using Web.Class;

namespace Web.Controls.LAIHAN
{
    public partial class UCLHShouLiBTNS : System.Web.UI.UserControl
    {
        #region 属性

        /// <summary>
        /// 用于保存其他关联控件
        /// </summary>
        private List<IUCLHOperate> componentList = new List<IUCLHOperate>();

        /// <summary>
        /// 来函ID
        /// </summary>
        public string LaiHanID { get; set; }

        /// <summary>
        /// 来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX { get; set; }

        #endregion

        #region 变量

        private SpHelper _sphelper = new SpHelper();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// 响应前台回调事件,完成受理
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            ValidateRS vrs;
            if (string.IsNullOrEmpty(this.LaiHanID))
            {
                e.Result = string.Join("|", e.Parameter, "-1", "缺少参数。");
                return;
            }
            //受理提交验证
            vrs = LaiHanLCTools.ValidateInfoSL(this.Parent);
            if (!vrs.IsSuccess)
            {
                e.Result = string.Join("|", e.Parameter, "-1", vrs.Msg);
                return;
            }
            //验证通过,执行受理等操作
            YS_LH_LAIHANXXProcess bllT = new YS_LH_LAIHANXXProcess();
            YS_LH_LAIHANXX laihan = bllT.SelectYS_LH_LAIHANXX(int.Parse(this.LaiHanID));
            if (laihan == null)
            {
                e.Result = string.Join("|", e.Parameter, "-1", "参数不正确。");
                return;
            }
            eLaiHanLCBH lcbh = e.Parameter == "th" ? eLaiHanLCBH.退回  //退回
                                : e.Parameter == "sl" ? eLaiHanLCBH.受理    //受理
                                : e.Parameter == "bsl" ?eLaiHanLCBH.不受理  //不受理
                                : eLaiHanLCBH.受理;

            laihan.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            laihan.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
            UCLHShenQingLY ucly = this.Parent.FindControl("UCLHShenQingLY") as UCLHShenQingLY;
            laihan.S_SHENQINGLY = ucly.LiYou;
            laihan.S_BEIZHU = ucly.BeiZhu;

            //if (string.IsNullOrEmpty(laihan.S_TONGYIBM) && 
            //    Helper.UnicodeHelper.IsNeedUnicode((eLaiHanLX)laihan.I_LAIHANLX))
            //{
            //    laihan.S_TONGYIBM = Helper.UnicodeHelper.GetUnicode();
            //}
            if (lcbh==eLaiHanLCBH.受理)
            {
                laihan.I_LIUCHENGBH = (int)eLaiHanLCBH.受理;
                laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.流程中;
            }
            else if(lcbh==eLaiHanLCBH.不受理)
            {
                laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.不受理;
            }
            else if (lcbh == eLaiHanLCBH.退回)
            {
                laihan.I_LIUCHENGBH = (int)eLaiHanLCBH.预登记;
                laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.流程中;
            }             
            bllT.InsertOrUpdate(laihan);
            //记录流程_受理
            YS_LH_LAIHANLCJLProcess lcbllT = new YS_LH_LAIHANLCJLProcess();
            YS_LH_LAIHANLCJL lcjl = new YS_LH_LAIHANLCJL();
            lcjl.D_CAOZUORQ = DateTime.Now;
            lcjl.D_STARTDATE = DateTime.Now;
            lcjl.D_ENDDATE = DateTime.Now;
            lcjl.I_CAOZUOR = LoginInfo.CurrentUser.UserID;
            lcjl.I_LAIHANLX = (int)this.LaiHanLX;
            lcjl.I_LIUCHENGBH = (int)lcbh;
            lcjl.ID = 0;
            lcjl.S_LAIHANBH = laihan.S_LAIHANBH;
            lcjl.S_LIUCHENGMC = lcbh.ToString();
            lcbllT.InsertOrUpdate(lcjl);
            //如果是受理,插入下一步流程
            if (lcbh == eLaiHanLCBH.受理)
            { 
                LaiHanLCTools.AddNextFlow(laihan,eLaiHanSPJG.同意,false);
            }
            //操作成功
            e.Result = string.Join("|", e.Parameter, "0", "操作成功");
        }

        #endregion

        #region 方法

        #endregion
    }
}